<template>
  <div style="width: 100%; height: 100%">
    <!-- <div class="jjb_text">{{ orgName }}&nbsp;值班日志</div> -->
    <div class="drawer_box" v-if="isShows">
      <el-form
        ref="ruleFormRef"
        :model="formDataJJB"
        label-position="right"
        label-width="140px"
        class="dd-edit-box"
      >
        <div class="date_box">
          <div>
            值班日期：
            {{ pshiftStartDate }} &nbsp; 至 &nbsp;
            {{ pshiftEndDate }}
            <!-- {{ getTimeRange().split("至")[0] }} &nbsp; 至 &nbsp;
            {{ getTimeRange().split("至")[1] }} -->
          </div>
          <div @click="tbrClick">填报人：{{ tbObj.reportUser }}</div>
          <!-- <div @click="tbrClick">填报人：{{ userName }}</div> -->
        </div>
        <div class="jjb border_table isTable" style="border-bottom: none">
          <el-table
            @cell-click="zbCellClick"
            border
            :data="tableDataZb"
            style="width: 100%"
          >
            <el-table-column prop="date" label="时间" width="160">
              <template #default="scope">
                <div v-if="scope.row.date == '白班'">
                  <div>
                    <span :style="{ color: getColor(scope.row) }">{{
                      "白班"
                    }}</span>
                    &nbsp;
                    <span>{{
                      scope.row.pshiftStart + "-" + scope.row.pshiftEnd
                    }}</span>
                  </div>
                </div>
                <div v-if="scope.row.date == '夜班'">
                  <div>
                    <span :style="{ color: getColor(scope.row) }">{{
                      "夜班"
                    }}</span>
                    &nbsp;
                    <span
                      >{{
                        scope.row.pshiftStart + "-" + scope.row.pshiftEnd
                      }}
                      次</span
                    >
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="" width="80" align="center" />
            <el-table-column prop="a" label="" width="80" align="center" />
            <el-table-column prop="names" label="" width="60" align="center" />
            <el-table-column prop="b" label="" align="center" />
            <el-table-column prop="c" label="" width="90" align="center" />
            <el-table-column prop="d" label="" width="80" align="center" />
          </el-table>
        </div>
        <div
          class="jj_box"
          style="display: flex; width: 100%; justify-content: space-between"
        ></div>

        <div
          class="jjb border_table isTable"
          style="border-bottom: none; border-top: none; margin-bottom: -1px"
        >
          <!-- 罪犯情况 -->
          <el-table
            border
            :span-method="objectSpanMethodCv"
            :data="ycqkList"
            style="width: 100%"
            @cell-click="ycsbCellClick"
          >
            <el-table-column prop="title" label="" width="80" align="center" />
            <el-table-column
              prop="type"
              label="类型"
              width="136"
              align="center"
            >
              <template #default="scope">
                {{ scope.row.exceptType + "情况" }}
              </template>
            </el-table-column>
            <el-table-column prop="content" label="情况描述">
              <template #default="scope">
                <div
                  style="display: flex"
                  v-for="(item, index) in getContet(scope.row.ids, '罪犯')"
                  :key="index"
                >
                  <div style="margin-right: 10px" class="yc_date">
                    {{
                      item.createDate.replace(/T/g, " ").split(" ")[0] +
                      " " +
                      item.createDate
                        .replace(/T/g, " ")
                        .split(" ")[1]
                        .split(":")[0] +
                      ":" +
                      item.createDate
                        .replace(/T/g, " ")
                        .split(" ")[1]
                        .split(":")[1]
                    }}
                  </div>
                  <div
                    style="
                      margin-right: 10px;
                      min-width: 120px;
                      text-align: left;
                    "
                    class="yc_content"
                  >
                    情况： {{ item.content }}
                  </div>
                  <!-- <div style="margin-right: 10px" class="yc_handleUserName">
                  {{ item.handleUserName }}
                </div>     -->

                  <div
                    v-if="item.handleContent"
                    style="margin-right: 10px"
                    class="yc_handleContent"
                  >
                    处理： {{ item.handleContent }}
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <!-- 机构情况 -->
        <div
          class="jjb border_table isTable"
          style="border-bottom: none; border-top: none; margin-bottom: -1px"
        >
          <el-table
            border
            :span-method="objectSpanMethod1"
            :data="jgqkArr"
            style="width: 100%"
          >
            <el-table-column prop="title" label="" width="80">
            </el-table-column>

            <el-table-column prop="" label="情况描述">
              <template #default="scope">
                <div
                  style="display: flex"
                  v-for="(item, index) in getContet(scope.row.ids, '机构')"
                  :key="index"
                >
                  <div style="margin-right: 10px" class="yc_date">
                    {{
                      item.createDate.replace(/T/g, " ").split(" ")[0] +
                      " " +
                      item.createDate
                        .replace(/T/g, " ")
                        .split(" ")[1]
                        .split(":")[0] +
                      ":" +
                      item.createDate
                        .replace(/T/g, " ")
                        .split(" ")[1]
                        .split(":")[1]
                    }}
                  </div>
                  <div
                    style="
                      margin-right: 10px;
                      min-width: 120px;
                      text-align: left;
                    "
                    class="yc_content"
                  >
                    类型： {{ item.exceptType }}
                  </div>
                  <div
                    style="
                      margin-right: 10px;
                      min-width: 120px;
                      text-align: left;
                    "
                    class="yc_content"
                  >
                    情况： {{ item.content }}
                  </div>

                  <div
                    style="margin-right: 10px"
                    v-if="item.handleContent"
                    class="yc_handleContent"
                  >
                    处理： {{ item.handleContent }}
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <!-- 监区情况 -->
        <div
          class="jjb border_table isTable"
          style="border-bottom: none; border-top: none; margin-bottom: -1px"
        >
          <el-table
            border
            :span-method="objectSpanMethod1"
            :data="jqqkArr"
            style="width: 100%"
          >
            <el-table-column prop="title" label="" width="80">
            </el-table-column>

            <el-table-column prop="" label="情况描述">
              <template #default="scope">
                <div
                  style="display: flex"
                  v-for="(item, index) in getContet(scope.row.ids, '监区')"
                  :key="index"
                >
                  <div style="margin-right: 10px" class="yc_date">
                    {{
                      item.createDate.replace(/T/g, " ").split(" ")[0] +
                      " " +
                      item.createDate
                        .replace(/T/g, " ")
                        .split(" ")[1]
                        .split(":")[0] +
                      ":" +
                      item.createDate
                        .replace(/T/g, " ")
                        .split(" ")[1]
                        .split(":")[1]
                    }}
                  </div>
                  <div
                    style="
                      margin-right: 10px;
                      min-width: 120px;
                      text-align: left;
                    "
                    class="yc_content"
                  >
                    类型： {{ item.exceptType }}
                  </div>
                  <div
                    style="
                      margin-right: 10px;
                      min-width: 120px;
                      text-align: left;
                    "
                    class="yc_content"
                  >
                    情况： {{ item.content }}
                  </div>

                  <div
                    style="margin-right: 10px"
                    v-if="item.handleContent"
                    class="yc_handleContent"
                  >
                    处理： {{ item.handleContent }}
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div
          class="jjb border_table isTable"
          style="border-bottom: none; border-top: none"
        >
          <!-- 工作交接 -->
          <el-table
            border
            :span-method="objectSpanMethod2"
            :data="gzjjList"
            style="width: 100%"
            @cell-click="gzjjCellClick"
          >
            <el-table-column prop="title" label="" width="80" align="center" />
            <el-table-column label="类型" width="136" align="center">
              <template #default="scope">
                <div v-if="scope.row?.type">
                  {{ scope.row.type }}
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="" label="情况描述">
              <template #default="scope">
                <div>
                  {{ scope.row.content }}
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>

      <!-- <div class="dialog-footer">
      <el-button type="primary" @click="jjbSave"> 保存 </el-button>
    </div> -->
    </div>
    <div v-else>
      <jjbSaveZj
        :listData="listData"
        :jcNub="jcNub"
        :orgIds="orgIds"
        :types="types"
        :data="dataSon"
        @childEventSon="childEventSon"
        :account="account"
        :ggjjObj="ggjjObj"
        :zfrs="zfrs"
      />
    </div>
  </div>
</template>

<script setup>
import { ElMessage } from "element-plus";
import http from "@/utils/api";
import jjbSaveZj from "./jjbSave.vue";

import {
  Search,
  Share,
  Upload,
  TakeawayBox,
  Refresh,
  Collection,
  Plus,
  Loading,
  FolderDelete,
  Back,
} from "@element-plus/icons-vue";
import {
  ref,
  watch,
  onMounted,
  onBeforeUnmount,
  reactive,
  onBeforeMount,
  nextTick,
  onUnmounted,
} from "vue";
import { defineProps, defineEmits, computed } from "vue";
const props = defineProps({
  sonData: {
    type: String,
    default: "",
  },
  orgIds: {
    type: Number,
    default: 22,
  },
  orgName: {
    type: String,
    default: "",
  },
  userName: {
    type: String,
    default: "",
  },
  account: {
    type: String,
    default: "",
  },

  dialogVisible10: {
    type: Boolean,
    default: true,
  },
  pidObj: {
    type: Object,
    default: {},
  },
  pids: {
    type: Number,
    default: 0,
  },
  jgqkList: {
    type: Array,
    default: [],
  },
  jqqkList: {
    type: Array,
    default: [],
  },
});

const countSameIds = (arr) => {
  const result = [];
  let i = 0;
  while (i < arr.length) {
    let count = 1;
    for (let j = i + 1; j < arr.length; j++) {
      if (arr[j].type === arr[i].type) {
        count++;
      } else {
        break;
      }
    }
    result.push({ a: i, b: count });
    i += count;
  }
  return result;
};

const objectSpanMethod1 = ({ row, column, rowIndex, columnIndex }) => {
  if (columnIndex === 0) {
    if (rowIndex == 0) {
      return {
        rowspan: 6,
        colspan: 1,
      };
    } else {
      return {
        rowspan: 0,
        colspan: 0,
      };
    }
  }

  return;
  //  console.log(rowIndex,columnIndex);
  //  console.log(countedIds.value,'countedIds');

  //  if (columnIndex === 0) { // 只对第一列进行合并
  //     let count = 1;
  //     for (let i = rowIndex + 1; i < gzqkList.value.length; i++) {
  //       if (gzqkList.value[i].type === row.type) {
  //         count++;
  //       } else {
  //         break;
  //       }
  //     }
  //     if (count > 1) {
  //         console.log(count,'count');

  //       return [count, 1]; // 返回合并的行数和列数
  //     }
  //     if( rowIndex == count){
  //         return [0, 0]
  //     }
  //   }
  //   return [1, 1]; // 默认不合并

  //  return
  if (columnIndex === 0) {
    let nubArr = countedIds.value;
    let nubs = 0;
    for (let i = 0; i < nubArr.length; i++)
      if (rowIndex == nubArr[i].a) {
        return {
          rowspan: nubArr[i].b,
          colspan: 1,
        };
      } else if (i == 0) {
        if (rowIndex > nubArr[i].a && rowIndex < nubArr[i].b) {
          nubs += nubArr[i].b;
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      } else {
        if (rowIndex > nubs && rowIndex < nubArr[i].b + nubArr[i].a) {
          nubs += nubArr[i].b;
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
  }
};
/**
 *
 * @param param0 return {rowspan: 1,colspan: 1 } 表示表格不变
return {rowspan: 2,colspan: 1 } 表示表格向下合并一个单元格
return {rowspan: 1,colspan: 2 } 表示表格向右合并一个单元格
return {rowspan: 0,colspan: 0 } 表示删除此单元格

 */

const objectSpanMethod2 = ({ row, column, rowIndex, columnIndex }) => {
  // if (columnIndex === 0 && rowIndex != 3) {
  //   if (rowIndex == 0) {
  //     return {
  //       rowspan: 1,
  //       colspan: 1,
  //     };
  //   } else {
  //     return {
  //       rowspan: 0,
  //       colspan: 0,
  //     };
  //   }
  // }
  // if (columnIndex === 1) {
  //   if (rowIndex == 3) {
  //     return {
  //       rowspan: 1,
  //       colspan: 2,
  //     };
  //   } else {
  //     return {
  //       rowspan: 1,
  //       colspan: 1,
  //     };
  //   }
  // }
};
const objectSpanMethodCv = ({ row, column, rowIndex, columnIndex }) => {
  if (columnIndex === 0) {
    if (rowIndex == 0) {
      return {
        rowspan: 5,
        colspan: 1,
      };
    } else {
      return {
        rowspan: 0,
        colspan: 0,
      };
    }
  }
};
const emit = defineEmits(["childEvent"]);
const types = ref("");
let dataSon = ref({});
const tableDataZb = ref([
  {
    date: "白班",
    name: "领导",
    a: "",
    names: "民警",

    d: "",
    b: "",
    c: "罪犯人数",
    pshiftStart: "",
    pshiftEnd: "",
  },
  {
    date: "夜班",
    name: "领导",
    a: "",
    names: "民警",
    d: "",
    b: "",
    c: "罪犯人数",
    pshiftStart: "",
    pshiftEnd: "",
  },
]);
let formDataJJB = ref({});
const getContet = (row, is) => {
  if (row && is == "罪犯") {
    let arrs = row.split(",").filter((item) => item != "undefined");

    const result = byYcData.value.filter((item) =>
      arrs.includes(String(item.id))
    );

    return result;
  }
  if (row && is == "工作") {
    let arrs = row.split(",").filter((item) => item != "undefined");

    const result = gzqkData.value.filter((item) =>
      arrs.includes(String(item.id))
    );

    return result;
  }
  if (row && is == "机构") {
    let arrs = row.split(",").filter((item) => item != "undefined");

    const result = props.jgqkList.filter((item) =>
      arrs.includes(String(item.id))
    );

    return result;
  }
  if (row && is == "监区") {
    let arrs = row.split(",").filter((item) => item != "undefined");

    const result = props.jqqkList.filter((item) =>
      arrs.includes(String(item.id))
    );

    return result;
  }

  //  return text.split(',').filter((itz)=>itz)
};

let zfrs = ref(0);
onBeforeMount(() => {});
let dateSfm = ref("");
let hour = ref("");
let daydata = ref("");
// 获取年月日 时
const getFormattedDateTime = () => {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, "0");
  const day = String(now.getDate()).padStart(2, "0");
  const hours = String(now.getHours()).padStart(2, "0");
  const minutes = String(now.getMinutes()).padStart(2, "0");
  const seconds = String(now.getSeconds()).padStart(2, "0");
  dateSfm.value = `${hours}:${minutes}:${seconds}`;
  hour.value = String(now.getHours()).padStart(2, "0");
  daydata.value = `${year}-${month}-${day}`;

  return `${year}-${month}-${day} ${hour.value}`;
};
let ycqkList = ref([
  {
    title: "指挥中心情况",
    exceptType: "视频调度",
    content: "",
  },
  {
    title: "指挥中心情况",
    exceptType: "值班收集",
    content: "",
  },
  {
    title: "指挥中心情况",
    exceptType: "巡查收集",
    content: "",
  },
]);

let ycqkids = ref([]);

let gzjjList = ref([
  {
    title: "强化信息研判分析",
    type: "指挥中心例行研判",
    content: "",
  },
  // {
  //   title: "强化信息研判分析",
  //   type: "",
  //   content: "",
  // },

  // {
  //   title: "强化信息研判分析",
  //   type: "",
  //   content: "",
  // },
]);
let byYcData = ref([]);
let gzqkData = ref([]);
let DutySList = ref([]);
let tbObj = ref({});
let pshiftEndDate = ref("");
let pshiftStartDate = ref("");
let bbzf = ref(0);
let ybzf = ref(0);
let gzqkIds = ref([]);

//异常情况数据
const getExceptionReportSelect = async () => {
  let obj = {
    page: 1,
    limit: 99,
    orgId: props.orgIds,
    exceptType: "",
    startDate: pshiftStartDate.value,
    endDate: pshiftEndDate.value,
    // startDate: getTimeRange().split("至")[0].split(" ")[0],
    // endDate: getTimeRange().split("至")[1].split(" ")[1],
    state: "0,1",
    reportState: "0,1,2,3,4",
    reportType: "zhzx",
  };
  let res = await http.znjw.ExceptionReportSelect(obj);
  if (!res) return;
  let ycArr = res.data.data;

  if (Array.isArray(ycArr)) {
    ycqkids.value = ycArr.map((item) => item.id);
    byYcData.value = ycArr;
    ycArr.forEach((item) => {
      if (item.content) {
        ycqkList.value.forEach((itz) => {
          if (itz.exceptType == item.exceptType) {
            itz["ids"] += "," + item.id;
          }
        });
      }

      if (item.exceptType == "指挥中心例行研判") {
        let str = "";
        str =
          item.reportState == 1
            ? "上报"
            : item.reportState == 2
            ? "通报"
            : item.reportState == 3
            ? "预警"
            : "汇总";
        gzjjList.value[0].content =
          item.content + " " + " " + "研判结果：" + str;
        // + ' '+'研判结果' + item.reportState == 1?'上报':item.reportState == 2?'通报':item.reportState == 3?'预警':'汇总'
      }
    });
  }
};

let listData = ref([]);
let jcNub = ref(0);
let peopleArr = ref([]);
//获取警察值班人员
const getZdbSelect = async () => {
  if (props.pidObj.children.length) {
    tableDataZb.value = props.pidObj.children.map((item) => {
      return {
        date: item.name,
        name: "领导",
        a: "",
        names: "民警",
        d: "",
        b: "",
        c: "罪犯人数",
        pshiftStart: item.start.slice(0, 5),
        pshiftEnd: item.end.slice(0, 5),
      };
    });
  }

  let res = await http.znjw.ZdbSelect({
    type: "zhzx",
    zbType: "1",
    orgId: props.orgIds || "",
    shift: props.pids,
    account: "",
    date: daydata.value,
  });
  if (!res) return;
  if (res.code == 0) {
    let zbArr = res.data;
    zbArr.length &&
      zbArr.forEach((item) => {
        item["zbryInfoArr"] =
          item?.zbry &&
          item.zbry.split(",").map((itz, index) => {
            return {
              name: item.zbry.split(",")[index],
              id: "",
              is: false,
              zbryAccount: item.zbryAccount.split(",")[index],
            };
          });
      });
    listData.value = zbArr;
    jcNub.value = 0;
    listData.value.forEach((item) => {
      if (item.zbry) {
        item.zbry.split(",").forEach((itz) => {
          peopleArr.value.push(itz);
          jcNub.value += 1;
        });
      }
    });
    listData.value.forEach((item) => {
      if (props.pidObj.children.length) {
        tableDataZb.value.forEach((itz) => {
          if (itz.date == item.pshiftName) {
            if (itz.name == item.shiftName) {
              itz.a = item.zbry;
            }
            if (itz.names == item.shiftName) {
              itz.b = item.zbry;
            }
          }
        });
      }

      // if (item.pshiftName == "白班") {
      //   if (item.shiftName == "领导") {
      //     tableDataZb.value[0].a = item.zbry;
      //   }
      //   if (item.shiftName == "民警") {
      //     tableDataZb.value[0].b = item.zbry;
      //   }
      // }

      // if (item.pshiftName == "夜班") {
      //   if (item.shiftName == "领导") {
      //     tableDataZb.value[1].a = item.zbry;
      //   }
      //   if (item.shiftName == "民警") {
      //     tableDataZb.value[1].b = item.zbry;
      //   }
      // }
    });
  }
};


let isShows = ref(true);
const ycsbCellClick = (row, clomm) => {
  if (clomm.label == "类型") {
    dataSon.value = row;
    types.value = "罪犯";
    isShows.value = false;
  }
};

//值班选人
const zbCellClick = (row, clomm) => {
  if (clomm.label != "时间") return;
  dataSon.value = row;
  types.value = "值班";
  let arrs = tableDataZb.value.filter((item) => item.date != row.date);
  zfrs.value = arrs[0].d;
  isShows.value = false;
};
//工作交接
const gzjjCellClick = (row) => {
  dataSon.value = row;
  dataSon.value.exceptType = row.type;
  types.value = "罪犯";
  isShows.value = false;
  // dataSon.value = row;
  // types.value = "工作交接";
  // isShows.value = false;
};

const getTimeRange = () => {
  const now = new Date();
  const targetTime = new Date(
    now.getFullYear(),
    now.getMonth(),
    now.getDate(),
    9,
    10
  );

  if (now > targetTime) {
    // 当前时间大于早上9:10，返回 "今日早上9:10到明天早上9:10"
    return `${formatDate(now)} 09:10 至 ${formatDate(
      new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1)
    )} 09:10`;
  } else {
    // 当前时间小于早上9:10，返回 "昨天早上9:10到今天早上9:10"
    return `${formatDate(
      new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1)
    )} 09:10 至 ${formatDate(now)} 09:10`;
  }
};
const formatDate = (date) => {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从0开始，需要加1
  const day = String(date.getDate()).padStart(2, "0");
  return `${year}-${month}-${day}`;
};
let reportUser = ref({});
let ggjjObj = ref({});
const getShiftDutySelect = async () => {
  let obj = {
    page: 1,
    limit: 200,
    orgId: props.orgIds,
    startDate: pshiftStartDate.value,
    endDate: pshiftEndDate.value,
    dutyType: "zhzx",
    // startDate: getTimeRange().split("至")[0].split(" ")[0] + " " + "09:10:00",
    // endDate: getTimeRange().split("至")[1] + ":00",
  };
  let res = await http.znjw.ShiftDutySelect(obj);
  if (res && res.code == 0) {
    DutySList.value = res.data.data;
    sessionStorage.setItem("formDataJJB", JSON.stringify({}));

    DutySList.value.forEach((item) => {
      tbObj.value.reportUser = item.reportUser;
      // formDataJJB.value["clsx"] =  item.clsx || "";
      // formDataJJB.value["remark"]= item.remark || "";
      // formDataJJB.value["gzyq"] =  item.gzyq || "";
      // formDataJJB.value["jnrs"] =  item.jnrs || 0;
      // formDataJJB.value["jwrs"] =  item.jwrs || 0;
      // formDataJJB.value["cjrs"] =  item.cjrs || 0;
      // formDataJJB.value["zyrs"] =  item.zyrs || 0;
      // formDataJJB.value["qyrs"] =  item.qyrs || 0;
      sessionStorage.setItem("formDataJJB", JSON.stringify(item));
      ggjjObj.value = item;
      reportUser.value = item.reportUser;
      //罪犯人数
      tableDataZb.value[0].d = item.ybzf;
      tableDataZb.value[1].d = item.bbzf;

      // 值班数据
      let zbArr = item.zdbItem;
      // getZdbSelect(zbArr)
      //工作情况
      // let gzArr = item.workItem;
      // getExceptionReportWorkSelect(gzArr);
      //异常情况
      // let ycArr = item.exceItem;
      // getExceptionReportSelect(ycArr);
      // 获取当前时间
    });
  }
};

const jjbSave = async () => {
  let arrIds = [...ycqkids.value];
  let gzqkId = [...gzqkIds.value];

  let res;
  if (!DutySList.value.length) {
    let obj = {
      orgId: props.orgIds,
      startDate: pshiftStartDate.value,
      endDate: pshiftEndDate.value,
      bbzf: bbzf.value,
      ybzf: ybzf.value,
      reportIds: arrIds.join(",") || "",
      workIds: gzqkId.join(",") || "",
      clsx: formDataJJB.value?.clsx || "",
      gzyq: formDataJJB.value?.gzyq || "",
      file: "",
      dutyType: "zhzx",
      remark: formDataJJB.value?.remark || "",
      jnrs: formDataJJB.value?.jnrs || 0,
      jwrs: formDataJJB.value?.jwrs || 0,
      cjrs: formDataJJB.value?.cjrs || 0,
      zyrs: formDataJJB.value?.zyrs || 0,
      qyrs: formDataJJB.value?.qyrs || 0,
      reportUser: tbObj.value?.reportUser || "",
    };
    console.log(obj, "交接班数据");

    res = await http.znjw.ShiftDutyAdd(obj);
  } else {
    let obj = {
      bbzf: bbzf.value || formDataJJB.value.bbzf,
      ybzf: ybzf.value || formDataJJB.value.ybzf,
      id: DutySList.value[0].id,
      clsx: formDataJJB.value.clsx || "",
      gzyq: formDataJJB.value.gzyq || "",
      remark: formDataJJB.value.remark,
      reportIds: arrIds.join(",") || "",
      workIds: gzqkId.join(",") || "",
      jnrs: formDataJJB.value.jnrs || 0,
      jwrs: formDataJJB.value.jwrs || 0,
      cjrs: formDataJJB.value.cjrs || 0,
      zyrs: formDataJJB.value.zyrs || 0,
      qyrs: formDataJJB.value.qyrs || 0,
      reportUser: tbObj.value?.reportUser || "",
    };
    res = await http.znjw.ShiftDutyUpdate(obj);
  }
  if (res && res.code == 0) {
    ElMessage({
      message: "保存完成",
      type: "success",
      plain: true,
    });
    emit("childEvent", "false");
  }
};
const childEventSon = (data) => {
  isShows.value = true;
  if (typeof data == "string") {
    if (data == "值班") {
      getZdbSelect();
      // getShiftDutySelect()
    }
    if (data == "罪犯") {
      getExceptionReportSelect();
      // getShiftDutySelect();
    }
  }
  if (data.value?.reportUser) {
    tbObj.value = data.value;
    jjbSave();
    return;
  }
  // 值班
  if (data?.isBs) {
    formDataJJB.value = data.data;

    if (data.type == "白班") {
      bbzf.value = Number(data.num);
    } else {
      ybzf.value = Number(data.num);
    }
    console.log("走了", data);

    jjbSave();

    return;
  }
  if (typeof data == "object" && !data?.value?.reportUser && !data?.isBs) {
    formDataJJB.value = data;

    jjbSave();
    return;
  }
};

const getColor = (row) => {
  // if(row.a || row.b){
  //   return '#2ab051'
  // }else{
  //   return 'red'
  // }
};

const tbrClick = () => {
  dataSon.value = reportUser.value;
  types.value = "填报人";
  isShows.value = false;
};

const getTimeRangeFun = (input) => {
  const today = new Date();
  const tomorrow = new Date(today);
  tomorrow.setDate(today.getDate() + 1);

  const formatDates = (date) => {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, "0");
    const day = String(date.getDate()).padStart(2, "0");
    return `${year}-${month}-${day}`;
  };

  if (input == 0) {
    return `${formatDates(today)} 至 ${formatDates(tomorrow)}`;
  } else if (input == 1) {
    return `${formatDates(today)} 至 ${formatDates(today)}`;
  }
};
// 机构数组
let jgqkArr = ref([
  {
    title: "机构情况",
    exceptType: "社情信息",
    content: "",
  },
]);
//监区数组
let jqqkArr = ref([
  {
    title: "监区情况",
    exceptType: "罪犯改造活动",
    content: "",
  },
]);

watch(
  () => props.dialogVisible10,
  (newValue, oldValue) => {
    if (newValue) {
      if (props.pidObj?.id) {
        pshiftStartDate.value = props.pidObj.curStartDate;
        pshiftEndDate.value = props.pidObj.curEndDate;
      }

      if (props.jgqkList.length) {
        props.jgqkList.forEach((item) => {
          if (item.content) {
            jgqkArr.value.forEach((itz) => {
              itz["ids"] += "," + item.id;
            });
          }
        });
      }
      if (props.jqqkList.length) {
        props.jqqkList.forEach((item) => {
          if (item.content) {
            jqqkArr.value.forEach((itz) => {
              itz["ids"] += "," + item.id;
            });
          }
        });
      }

      //d当前时间
      getFormattedDateTime();
      isShows.value = true;
      getZdbSelect();
      //罪犯情况
      getExceptionReportSelect();

      //交接班列表数据
      getShiftDutySelect();
    }
  },
  {
    deep: true, // 深度监听
    immediate: true, // 立即触发回调
  }
);
</script>

<style scoped lang="scss">
::v-deep .isTable {
  .el-table {
    background-color: rgb(8, 32, 78) !important;
    .el-table tr {
      background-color: rgb(8, 32, 78) !important;
    }
    .el-table thead tr {
      display: none !important;
    }
    .cell {
      height: auto;
      color: #fff;
      text-align: center;
      // border: 1px solid #ccc;
      background: rgb(8, 32, 78) !important;
      font-size: 12px;
      line-height: 34px;
    }
    --el-table-border-color: rgb(5, 112, 146);
  }
}
.border_table {
  border-right: none;
}

.jjb_text {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  top: 40px;
  font-size: 16px;
  font-weight: bold;
}
.date_box {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0 14px;
  padding-right: 64px;
  color: white;
  margin-bottom: 6px;
}

.wrap_text {
  width: 60px;
  overflow-wrap: break-word; /* 新版浏览器支持 */
}
.yc_table {
  width: 100%;
  overflow-y: scroll;
  color: white;
  // height: 66px;
  height: 200px;
  .table_item {
    width: 100%;
    height: 30px;
    cursor: pointer;
    height: 25px;
    justify-content: space-evenly;
    font-size: 12px;
  }
}
.jj_box {
  margin-bottom: -1px;
  font-size: 14px;
}
.drawer_box {
  width: 100%;
  height: 660px;
  overflow-y: scroll;
  box-sizing: border-box;
  padding: 0 20px;
  position: relative;
  .dialog-footer {
    position: absolute;
    bottom: -50px;
    right: 2px;
    // font-size: 18px;
  }
}
</style>
